import { useMobildVerify } from '@/hooks/useDataVerify.js';

/**
 * 表单的校验规则
 * @param {string} key rules规则对象的属性名称
 * @returns 对应表单的校验信息
 */
export default function useRules (key) {
  const rules = {

    /* 字典类型 */
    dictTypeRules: {
      dictKey: [
        { required: true, message: '请输入字典类型', trigger: 'blur' }
      ],
      dictValue: [
        { required: true, message: '请输入字典类型名称', trigger: 'blur' }
      ]
    },
    /* 字典值 */
    dictDataRules: {
      dictLabel: [
        { required: true, message: '请输入字典标签', trigger: 'blur' }
      ],
      dictValue: [
        { required: true, message: '请输入字典值', trigger: 'blur' }
      ],
      dictSort: [{ required: true, message: '请输入排序值', trigger: 'blur' }]
    },
    /* 物流公司信息[expressInfo.vue] */
    expressInfoRules: {
      ex_com: [
        { required: true, message: '请输入物流公司编号', trigger: 'blur' }
      ],
      ex_name: [
        { required: true, message: '请输入物流公司名称', trigger: 'blur' }
      ],
      ex_mobile: [
        { required: true, message: '请输入物流公司联系电话', trigger: 'blur' }
      ],
      ex_logo: [
        { required: true, message: '请上传物流公司logo', trigger: 'blur' }
      ],
      sort: [{ required: true, message: '请输入排序顺序', trigger: 'blur' }]
    },
    /* 角色信息[roleInfoRules.vue] */
    roleInfoRules: {
      name: [{ required: true, message: '角色名称必填', trigger: 'blur' }]
    },
    /* 广告类型[advertisingType.vue] */
    advertisingTypeRules: {
      type_name: [
        { required: true, message: '请输入页面名称', trigger: 'blur' }
      ],
      sort: [{ required: true, message: '请输入排序顺序', trigger: 'blur' }]
    },
    /* 广告信息[advertisingInfo.vue] */
    advertisingInfoRules: {
      banner_name: [
        { required: true, message: '请填写广告名称', trigger: 'blur' }
      ],
      position: [
        { required: true, message: '请选择广告位置', trigger: 'blur' }
      ],
      banner_type_id: [
        { required: true, message: '请选择广告类型', trigger: 'blur' }
      ],
      sort: [{ required: true, message: '请填写排序', trigger: 'blur' }],
      image: [{ required: true, message: '请上传广告图片', trigger: 'blur' }]
    },
    /* 分类管理[categoriesInfo.vue] */
    categoriesRules: {
      name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }],
      sort: [{ required: true, message: '请输入排序顺序', trigger: 'blur' }]
    },
    /* 运费模板管理[freighTemplate.vue] */
    freighTemplateRules: {
      deliver_name: [
        { required: true, message: '请填写模板名称', trigger: 'blur' }
      ]
    },

    /* 红包管理[redEnvelopeManagement.vue] */
    redEnvelopeManagementRules: {
      mobile: [
        { required: true, validator: useMobildVerify, trigger: 'blur' }
      ],
      amount: [{ required: true, message: '请填写充值金额', trigger: 'blur' }]
    },

    /* 客服分类信息[customerServicClass.vue] */
    customerServicClassRules: {
      name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }],
      sort: [{ required: true, message: '请输入排序顺序', trigger: 'blur' }],
      start_time: [
        { required: true, message: '请输入在线时间', trigger: 'blur' }
      ]
    },
    /* 客服信息[customerServicList.vue] */
    customerServicListRules: {
      name: [{ required: true, message: '请填写客服名称', trigger: 'blur' }],
      customer_service_category_id: [
        { required: true, message: '请选择客服分类', trigger: 'blur' }
      ],
      sort: [{ required: true, message: '请填写排序', trigger: 'blur' }],
      mobile: [
        { required: true, validator: useMobildVerify, trigger: 'blur' }
      ]
    },
    /* 用户信息[userInfo.vue.vue] */
    userRules: {
      user_name: [
        { required: true, message: '请填写用户名', trigger: 'blur' }
      ],
      nick_name: [{ required: true, message: '请填写昵称', trigger: 'blur' }],
      role_id: [{ required: true, message: '请选择角色', trigger: 'blur' }],
      agency_id: [{ required: true, message: '请选择组织', trigger: 'blur' }],
      mobile: [{ required: true, validator: useMobildVerify, trigger: 'blur' }]
    },
    /* 软件更新信息[softwareUpgradeRules.vue] */
    softwareUpgradeRules: {
      type: [{ required: true, message: '平台类型必选', trigger: 'blur' }],
      version_code: [
        { required: true, message: '版本号必填', trigger: 'blur' }
      ],
      descriptions: [
        { required: true, message: '描述信息必填', trigger: 'blur' }
      ]
    },
    /* 个人信息[personalInfo.vue] */
    personalInfoRules: {
      nick_name: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
      mobile: [{ required: true, validator: useMobildVerify, trigger: 'blur' }]
    },
    /* 商品信息[mallGoodsInfo.vue] */
    mallGoodsInfoRules: {
      category_ids: [
        { required: true, message: '请选择商品分类', trigger: 'blur' }
      ],
      goods_name: [
        { required: true, message: '请填写商品名称', trigger: 'blur' }
      ],
      status: [
        { required: true, message: '请选择商品状态', trigger: 'blur' }
      ],
      deliver_id: [
        { required: true, message: '请选择运费模板', trigger: 'blur' }
      ],
      cost_price: [
        { required: true, message: '请填写成本价', trigger: 'blur' }
      ],
      wholesale_price: [
        { required: true, message: '请填写批发价', trigger: 'blur' }
      ],
      retail_price: [
        { required: true, message: '请填写零售价', trigger: 'blur' }
      ],
      stock_total: [
        { required: true, message: '请填写库存', trigger: 'blur' }
      ],
      sales_initial: [
        { required: true, message: '请填写已售基数', trigger: 'blur' }
      ],
      goods_no: [{ required: true, message: '请填写货号', trigger: 'blur' }],
      platform_type: [
        { required: true, message: '请填写发布平台', trigger: 'blur' }
      ]
    }
  }
  if (!rules[key]) console.error('请传入正确的表单验证的名称');
  return rules[key];
}